//
//  WKWebController.h
//  云成绩
//

#import <UIKit/UIKit.h>
#import <WebKit/WebKit.h>

NSString * cookieFromURL(NSURL *url);

#pragma mark - Web协议
@class WKWebHandle;
@protocol WKDelegate <WKUIDelegate, WKNavigationDelegate>

@optional
- (NSArray<__kindof WKWebHandle *> *)createWebViewHandles;

- (WKUserContentController *)createUserContentController;

- (NSArray<__kindof WKUserScript *> *)createUserScripts;

- (__kindof WKWebView *)createWebViewByFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration;

- (void)onJavaScriptHandleError:(NSString *)message;

- (void)onJavaScriptShare:(NSDictionary *)share;

- (void)onJavaScriptBackApp:(id)obj;
@end

#pragma mark - Web控制器
@interface WKWebController : UIViewController

@property (nonatomic, weak) id<WKDelegate> delegate;

@property (nonatomic, weak) WKWebView *webView;
@property (nonatomic, weak) UIProgressView *progressView;

@property (nonatomic, copy) NSURL *url;

- (void)appOpenURL:(NSURL *)url;
- (void)loadURL:(NSURL *)url;

@end


#pragma mark - JS交互接口
@interface WKWebHandle : NSObject <WKScriptMessageHandler>

@property (nonatomic, copy) NSString *name;
@property (nonatomic, weak) id target;
@property (nonatomic, assign) SEL action;

@property (nonatomic, weak) WKWebController *controller;

- (instancetype)initWithName:(NSString *)name Target:(id)target Action:(SEL)action;

@end

@interface WKWebView (LoadRequest)

- (WKNavigation *)loadMutableRequest:(NSMutableURLRequest *)request useCookie:(NSString *)cookieString;
- (WKNavigation *)loadURL:(NSURL *)url;

@end
